<html>
<head><meta charset="utf-8"><title>Object safety · wg-async-foundations/stream-trait-rfc · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/index.html">wg-async-foundations/stream-trait-rfc</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html">Object safety</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="220720643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/220720643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alice Ryhl <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#220720643">(Dec 22 2020 at 18:38)</a>:</h4>
<p>There are some object-safety related issues with having <code>next</code> on <code>Stream</code> itself.<br>
See my comment for more: <a href="https://github.com/rust-lang/rust/pull/79023#pullrequestreview-557269331">https://github.com/rust-lang/rust/pull/79023#pullrequestreview-557269331</a><br>
Any thoughts?</p>



<a name="221331955"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/221331955" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#221331955">(Jan 01 2021 at 02:56)</a>:</h4>
<p>Yeah, the problem seems pretty fundamental</p>



<a name="221331956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/221331956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#221331956">(Jan 01 2021 at 02:56)</a>:</h4>
<p>I wrote a doc on it: <a href="https://hackmd.io/@CTI_5_5PSN2-6VHLeF5YuQ/r1Af46oaD/edit">The <code>Stream::next()</code> problem</a></p>



<a name="221353102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/221353102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#221353102">(Jan 01 2021 at 14:05)</a>:</h4>
<p>We should just land without it initially imo</p>



<a name="222195667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/222195667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nell Shamrell-Harrington <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#222195667">(Jan 09 2021 at 23:51)</a>:</h4>
<p>I agree - I'm going to take it out of the RFC to hopefully get it to acceptance</p>



<a name="222197878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/222197878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nell Shamrell-Harrington <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#222197878">(Jan 10 2021 at 00:50)</a>:</h4>
<p>Done! <a href="https://github.com/rust-lang/rfcs/pull/2996">https://github.com/rust-lang/rfcs/pull/2996</a></p>



<a name="222702784"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/222702784" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#222702784">(Jan 14 2021 at 10:54)</a>:</h4>
<p>I'll update the Stream PR this Friday to reflect the change in the RFC; was on vacation for the past few weeks so didn't have a chance to do it sooner.</p>



<a name="222971703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/222971703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#222971703">(Jan 16 2021 at 09:35)</a>:</h4>
<p>Thanks <span class="user-mention" data-user-id="211722">@Yoshua Wuyts</span> !</p>



<a name="223000328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/223000328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nell Shamrell-Harrington <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#223000328">(Jan 16 2021 at 19:12)</a>:</h4>
<p>Hey all - there's some more discussion on the RFC, but it's unclear to me whether it's something that would block acceptance of this RFC</p>



<a name="223000333"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/223000333" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nell Shamrell-Harrington <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#223000333">(Jan 16 2021 at 19:12)</a>:</h4>
<p>Would appreciate if people would weigh in when they have some time</p>



<a name="223142545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/223142545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Gilcher <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#223142545">(Jan 18 2021 at 16:43)</a>:</h4>
<p><span class="user-mention" data-user-id="225192">@Nell Shamrell-Harrington</span> weighted in with the very heavyweight suggestion of "should channels actually fulfill the Stream interface?" <a href="https://github.com/rust-lang/rfcs/pull/2996#issuecomment-762302488">https://github.com/rust-lang/rfcs/pull/2996#issuecomment-762302488</a> (I think they shouldn't)</p>



<a name="223142637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/223142637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Gilcher <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#223142637">(Jan 18 2021 at 16:44)</a>:</h4>
<p>I think they raise a good question, though.</p>



<a name="223186334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/223186334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nell Shamrell-Harrington <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#223186334">(Jan 19 2021 at 04:26)</a>:</h4>
<p>I think I'm leaning toward your viewpoint as well. Any ideas on how we would communicate that? Documentation? Checks in the compiler? Something else?</p>



<a name="223214241"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/223214241" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Gilcher <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#223214241">(Jan 19 2021 at 11:32)</a>:</h4>
<p>Good question - they've since added another post saying that the effect is true for other structures, maybe it's worth giving an example there?</p>



<a name="223214283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/223214283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Gilcher <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#223214283">(Jan 19 2021 at 11:32)</a>:</h4>
<p>I actually think it's a good discriminator, making a Stream something that stays in location and spills out its goods there :D</p>



<a name="224077916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224077916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224077916">(Jan 26 2021 at 17:58)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116883">tmandry</span> <a href="#narrow/stream/249502-wg-async-foundations.2Fstream-trait-rfc/topic/Object.20safety/near/221331956">said</a>:</p>
<blockquote>
<p>I wrote a doc on it: <a href="https://hackmd.io/@CTI_5_5PSN2-6VHLeF5YuQ/r1Af46oaD/edit">The <code>Stream::next()</code> problem</a></p>
</blockquote>
<p>I was looking at this today, and noticed that <code>Iterator</code> has a very similar method to <code>Stream::next</code>: <code>Iterator::map</code> (which has no <code>Self : Sized</code> bound, as we'd prefer for <code>Stream::next</code>)</p>
<p>Iterator IS object-safe (provided methods appear to not affect object safety), and map can be called on a &amp;mut dyn Iterator:<br>
<a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=7dd33d65c9eff4abb0679deec2bf68c4">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=7dd33d65c9eff4abb0679deec2bf68c4</a></p>
<p>I think the difference is Iterator::map takes <code>self</code> and Stream::next takes <code>&amp;mut self</code>. Is that the difference that causes iterator to just work our and Stream::next have method resolution issues?  (looking at the method resolution algorithm</p>



<a name="224220920"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224220920" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224220920">(Jan 27 2021 at 17:58)</a>:</h4>
<p>I'm very late to the party here, but <span class="user-mention" data-user-id="116883">@tmandry</span> is there a reason we can't use <code>where Self: Sized</code> on the <code>next()</code> method?</p>



<a name="224221036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224221036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224221036">(Jan 27 2021 at 17:58)</a>:</h4>
<p>I don't think it makes <code>next</code> harder to use in particular, since typically if you have a <code>dyn Stream</code>, you'll have a <code>Box&lt;dyn Stream&gt;</code>, and that is a sized type that implements <code>Stream</code></p>



<a name="224221058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224221058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224221058">(Jan 27 2021 at 17:58)</a>:</h4>
<p>I'm skimming the doc but I didn't notice this clearly discussed</p>



<a name="224246602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224246602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224246602">(Jan 27 2021 at 21:01)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> the problem is the method dispatch doesn't actually work that way</p>



<a name="224246659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224246659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224246659">(Jan 27 2021 at 21:01)</a>:</h4>
<p>here's a <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=1d941bb89e9c9c55d663ec9a11c12739">playground</a> that shows what I'm talking about</p>



<a name="224246679"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224246679" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224246679">(Jan 27 2021 at 21:01)</a>:</h4>
<p>I can sort of imagine, but ok</p>



<a name="224267137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224267137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224267137">(Jan 28 2021 at 00:02)</a>:</h4>
<p>wow...Iterator::map actually does have a Self: Sized requirement but it doesn't actually show in rustdoc: <a href="https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.map">https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.map</a> vs <a href="https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#625">https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#625</a></p>
<p>is this a rustdoc bug?</p>



<a name="224267474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224267474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224267474">(Jan 28 2021 at 00:06)</a>:</h4>
<p>also it appears the difference in self vs &amp;mut self makes all the difference: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=0bdebf1faaa318d59ef2776261e9c4f0">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=0bdebf1faaa318d59ef2776261e9c4f0</a></p>



<a name="224312037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224312037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224312037">(Jan 28 2021 at 11:12)</a>:</h4>
<p><span class="user-mention" data-user-id="116883">@tmandry</span> so..hm...we could probably fix this in the way we handle method dispatch</p>



<a name="224312169"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224312169" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224312169">(Jan 28 2021 at 11:14)</a>:</h4>
<p>We need to document better those rules there :) I always have to kind of "re-remember" what's going on</p>



<a name="224312220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224312220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224312220">(Jan 28 2021 at 11:15)</a>:</h4>
<p>I guess I am a bit surprised</p>



<a name="224312816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224312816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224312816">(Jan 28 2021 at 11:21)</a>:</h4>
<p>OK, so, <span class="user-mention" data-user-id="116883">@tmandry</span> -- this playground is sort of incomplete, in that it doesn't include <code>impl Stream for &amp;mut S</code> and for <code>Box&lt;S&gt;</code>. If you add those, dispatch works as expected (<a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=922dd26b2e3180ce1f5a58c656164739">playground</a>). However, to actually <em>implement</em> <code>next()</code> for those cases will require copy-and-pasting the implementation; you can't just call <code>S::next(self)</code> because that would require that <code>S: Sized</code></p>



<a name="224312821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224312821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224312821">(Jan 28 2021 at 11:21)</a>:</h4>
<p>but that seems...ok</p>



<a name="224312863"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224312863" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224312863">(Jan 28 2021 at 11:22)</a>:</h4>
<p>we can call a helper method or something</p>



<a name="224312892"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224312892" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224312892">(Jan 28 2021 at 11:22)</a>:</h4>
<p>In particular, the dispatch rules are that we try</p>
<ul>
<li>by-value</li>
<li>by-ref</li>
<li>by-mut-ref</li>
</ul>
<p>in that order, and then we try adding derefs.</p>



<a name="224312912"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224312912" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224312912">(Jan 28 2021 at 11:22)</a>:</h4>
<p>In this case, we get <code>by-mut-ref</code> on <code>&amp;mut dyn Stream</code> or <code>Box&lt;dyn Stream&gt;</code> and it works, so we never proceed to add any derefs</p>



<a name="224312958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224312958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224312958">(Jan 28 2021 at 11:23)</a>:</h4>
<p>but if you lack the impls, we will add a deref, when means we would wind up invoking <code>by-mut-ref</code> on <code>dyn Stream</code> and get the "must be sized" error</p>



<a name="224312963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224312963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224312963">(Jan 28 2021 at 11:23)</a>:</h4>
<p>am I missing something here?</p>



<a name="224358194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224358194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224358194">(Jan 28 2021 at 17:03)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> in the <code>Iterator::map</code> case, the &amp;mut I and Box&lt;I&gt; impls don't need to reimplement the provided <code>map</code> method (actually they do reimplement some other provided methods but idk why), but dispatch seems to work. Is that because we try the by-value rule first?</p>



<a name="224358327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224358327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224358327">(Jan 28 2021 at 17:04)</a>:</h4>
<p>I have to look more closely, I think the other problem was <code>Unpin</code></p>



<a name="224367128"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224367128" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224367128">(Jan 28 2021 at 18:01)</a>:</h4>
<p>i.e., you can't call <code>S::next</code> because that would require that <code>S: Unpin</code> and you don't want to require that</p>



<a name="224383120"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224383120" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224383120">(Jan 28 2021 at 19:50)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> I don't know if you saw <a href="https://hackmd.io/hggAwCSqTj-0YQJi4y9gjg">this doc</a> on the issue</p>



<a name="224383169"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224383169" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224383169">(Jan 28 2021 at 19:50)</a>:</h4>
<p>I saw it</p>



<a name="224383179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224383179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224383179">(Jan 28 2021 at 19:50)</a>:</h4>
<p>but I only briefly read it</p>



<a name="224383191"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224383191" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224383191">(Jan 28 2021 at 19:50)</a>:</h4>
<p>I'll read it more carefully :)</p>



<a name="224383845"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224383845" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224383845">(Jan 28 2021 at 19:55)</a>:</h4>
<p>but yeah when I last looked it didn't seem like I could get the <code>&amp;mut (dyn Stream + Unpin)</code> case to work</p>



<a name="224383902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224383902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224383902">(Jan 28 2021 at 19:56)</a>:</h4>
<p>and it doesn't seem like it's working in that playground link</p>



<a name="224384342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224384342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224384342">(Jan 28 2021 at 19:59)</a>:</h4>
<p>I guess  I can build a branch of <span class="user-mention" data-user-id="211722">@Yoshua Wuyts</span>'s PR and experiment</p>



<a name="224387618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224387618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224387618">(Jan 28 2021 at 20:25)</a>:</h4>
<p>I'm trying to remember why method dispatch was choosing the "wrong" method</p>



<a name="224387755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224387755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224387755">(Jan 28 2021 at 20:26)</a>:</h4>
<p>it seemed clear when I wrote that doc, but doesn't seem so clear from reading it <span aria-label="sweat" class="emoji emoji-1f613" role="img" title="sweat">:sweat:</span></p>



<a name="224388003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224388003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224388003">(Jan 28 2021 at 20:29)</a>:</h4>
<p>I think it might be that despite having a receiver of type <code>&amp;mut dyn (Stream&lt;Item = ()&gt; + Unpin)</code>, the algorithm starts with <code>dyn (Stream&lt;Item = ()&gt; + Unpin)</code> somehow</p>



<a name="224426753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224426753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224426753">(Jan 29 2021 at 03:23)</a>:</h4>
<p>Okay, that wasn't quite right</p>



<a name="224426771"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224426771" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224426771">(Jan 29 2021 at 03:23)</a>:</h4>
<p>I <del>somehow</del> got the algorithm pseudocode wrong in my doc</p>



<a name="224427448"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224427448" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224427448">(Jan 29 2021 at 03:37)</a>:</h4>
<p>it's quite subtle and the logic isn't all in one place. also I wrote that part late at night :(</p>



<a name="224428095"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224428095" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224428095">(Jan 29 2021 at 03:52)</a>:</h4>
<p>but what it comes down to is that we <em>always</em> consider inherent methods before extension methods, and the method provided by the <code>Stream</code> trait is considered an inherent method of <code>dyn Stream</code></p>



<a name="224428127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224428127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224428127">(Jan 29 2021 at 03:53)</a>:</h4>
<p>notably, we consider inherent methods of "adjusted" types, like autoderefs (so <code>dyn Stream</code> in this case)</p>



<a name="224428132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224428132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224428132">(Jan 29 2021 at 03:53)</a>:</h4>
<p>before ever considering extension methods, even those impl'd directly on the original type itself (<code>&amp;mut dyn ...</code> here)</p>



<a name="224428133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224428133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224428133">(Jan 29 2021 at 03:53)</a>:</h4>
<p>I updated the <a href="https://hackmd.io/hggAwCSqTj-0YQJi4y9gjg#Dispatch-algorithm">dispatch algorithm</a> in the doc</p>



<a name="224428301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224428301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224428301">(Jan 29 2021 at 03:57)</a>:</h4>
<p>I think changing this "priority" scheme would be a breaking change</p>



<a name="224428411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224428411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224428411">(Jan 29 2021 at 03:59)</a>:</h4>
<p>one non-breaking way to fix it is to consider the where clauses on the methods themselves before picking them, which would cause us to skip over the inherent method causing our compiler error, and pick the extension method instead</p>



<a name="224428481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224428481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224428481">(Jan 29 2021 at 04:00)</a>:</h4>
<p>(this is strictly more permissive, since we are giving you a "second chance" during method dispatch resolution, essentially)</p>



<a name="224428491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224428491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224428491">(Jan 29 2021 at 04:00)</a>:</h4>
<p>but this and other approaches are included in the doc</p>



<a name="224428583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/224428583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#224428583">(Jan 29 2021 at 04:02)</a>:</h4>
<p>In case the above is hard to follow:</p>
<ul>
<li>an <strong>inherent method</strong> is a method defined inside <code>impl Foo {}</code> or <code>trait Bar {}</code></li>
<li>an <strong>extension method</strong> is a method defined inside <code>impl Bar for Foo {}</code></li>
</ul>



<a name="225193903"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/225193903" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#225193903">(Feb 04 2021 at 17:34)</a>:</h4>
<p><span class="user-mention" data-user-id="116883">@tmandry</span> that makes sense, I wondered if it was to do with the "inherent-ness" of dyn types</p>



<a name="225193945"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/225193945" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#225193945">(Feb 04 2021 at 17:34)</a>:</h4>
<p>I wonder</p>



<a name="225193981"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/225193981" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#225193981">(Feb 04 2021 at 17:34)</a>:</h4>
<p>that is probably backwards compatible</p>



<a name="225194003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/225194003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#225194003">(Feb 04 2021 at 17:34)</a>:</h4>
<p>we already have special logic identifying those methods for the purposes of deciding if a trait is object safe</p>



<a name="225194113"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/225194113" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#225194113">(Feb 04 2021 at 17:35)</a>:</h4>
<p>it could exclude them from being inherent</p>



<a name="225194135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/225194135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#225194135">(Feb 04 2021 at 17:35)</a>:</h4>
<p>I'm curious why my playground wasn't encountering said problem?</p>



<a name="225194289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/225194289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#225194289">(Feb 04 2021 at 17:36)</a>:</h4>
<p>(<a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=2ae78226216e3e4c2ef984b4045a2a7d">playground</a></p>



<a name="225213042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/225213042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#225213042">(Feb 04 2021 at 19:52)</a>:</h4>
<p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=d728d6de2e1966b56767ede460d2dd4f">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=d728d6de2e1966b56767ede460d2dd4f</a> the problem is just <code>&amp;mut dyn</code>'s right?</p>



<a name="225216243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/225216243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#225216243">(Feb 04 2021 at 20:15)</a>:</h4>
<p>^ yep it seems like it's just <code>&amp;mut dyn</code></p>



<a name="226507581"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/226507581" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#226507581">(Feb 16 2021 at 12:34)</a>:</h4>
<p>I see</p>



<a name="226507601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/226507601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#226507601">(Feb 16 2021 at 12:34)</a>:</h4>
<p>/me thinks</p>



<a name="226749056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/226749056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#226749056">(Feb 18 2021 at 00:23)</a>:</h4>
<p>Is the reason only <code>&amp;mut self</code> fails something like:<br>
We have these 4 impls</p>
<ol>
<li>
<p><code>impl Iterator for dyn Iterator</code> (I think the compiler generates something like this?)<br>
<code>map</code>'s self: dyn Iterator (Self: !Sized)</p>
</li>
<li>
<p><code>impl&lt;I: Iterator + ?Sized&gt; Iterator for &amp;mut I</code><br>
<code>map</code>'s self: &amp;mut dyn Iterator</p>
</li>
<li>
<p><code>impl Stream for dyn Stream</code> (I think the compiler generates something like this?)<br>
<code>map</code>'s self: &amp;mut dyn Iterator (but Self: !Sized)</p>
</li>
<li>
<p><code>impl&lt;S: Stream + ?Sized&gt; Stream for &amp;mut S</code><br>
<code>next</code>'s self = &amp;mut &amp;mut dyn Iterator</p>
</li>
</ol>
<p>So for <code>self</code> things like Iterator::map, when <code>adj_self_ty = self_ty = &amp;mut dyn Iterator</code> <a href="https://github.com/rust-lang/rust/issues/1">#1</a> isnt a candidate and is skipped, but in the &amp;mut Self case, <code>adt_self_ty = self_ty = &amp;mut dyn Iterator</code> matches <a href="https://github.com/rust-lang/rust/issues/3">#3</a> and it is before we try <code>adt_self_ty = &amp;mut self_ty</code>and match <a href="https://github.com/rust-lang/rust/issues/4">#4</a> correctly? (this is me only starting to understand what <code>xform_self</code> does)</p>



<a name="226835342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/226835342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#226835342">(Feb 18 2021 at 16:12)</a>:</h4>
<p>Though I could be wrong. while writing <a href="https://github.com/rust-lang/rust/issues/965">#965</a> I saw that if you a "reborrowing" a &amp;mut to a method that takes &amp;Self its even worse: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=a464f7d3df03f2189537531c306038f5">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=a464f7d3df03f2189537531c306038f5</a></p>



<a name="226835431"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/226835431" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#226835431">(Feb 18 2021 at 16:13)</a>:</h4>
<p>requiring <code>(&amp;&amp;*mut_ref_dyn_obj).method_that_takes_shared_reference()</code>to resolve</p>



<a name="229066112"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object%20safety/near/229066112" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gus Wynn <a href="https://rust-lang.github.io/zulip_archive/stream/249502-wg-async-foundations/stream-trait-rfc/topic/Object.20safety.html#229066112">(Mar 06 2021 at 05:03)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> on twitter suggested that this may be resolvable without changing the language, and suggested I make an issue: <a href="https://github.com/rust-lang/rust/issues/82825">https://github.com/rust-lang/rust/issues/82825</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>